home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
PowerPlant
/
AGA Classes 1.2
/
Utilities
/
LAGALittleArrows.cp
< prev
next >
Wrap
Text File
|
1996-06-30
|
7KB
|
269 lines
// ===========================================================================
// LAGALittleArrows.cp
// ===========================================================================
// “Apple Grayscale Appearance” compliant little-arrows control. Auto-repeats
// if held down. Uses the same PPob as LStdCheckBox
//
// Copyright 1996 by Michael™ Hamel of ADInstruments NZ Ltd, mhamel@adi.co.nz
//
// You may use this source code in any application (commercial, shareware, freeware,
// postcardware, etc), without acknowledgment, but may not remove this notice.
//
// You may not sell this source code in any form. This source code may be placed on
// publicly accessible archive sites and source code disks. It may not be placed on
// for-profit archive sites and source code disks without the permission of the author.
//
// This source code is distributed "as is", without any warranty. Use it at your own
// risk.
//
// This class requires AGAColors.cp to be present in your project
//
// Version : 1.2
//
// Change History (most recent first, date in US form : mm/dd/yy):
//
// 06/30/96 ca Public release of version 1.2
// 06/27/96 ca Changed checks for disabled state (check on triState_On instead of triState_Off)
// in order that triState_Latent state is drawn as disabled
// 06/05/96 ca Added RegisterClass method to ease registry
// Increased version to 1.2
// 05/21/96 M™H Initial version set to 1.1 to be put with other AGA classes
//
// To Do:
//
#include "LAGALittleArrows.h"
#include "AGAColors.h"
#include <UTextTraits.h>
#include <UDrawingState.h>
#include <UDrawingUtils.h>
#include <LStream.h>
//------------------------- LAGALittleArrows -------------------------------
enum {
kArrowWidth = 13,
kArrowHeight = 12,
kDownArrow = 2,
kUpArrow = 1,
kTextStart = 18
};
// begin <06/05/96 ca>
void LAGALittleArrows::RegisterClass ()
{
URegistrar::RegisterClass(LAGALittleArrows::class_ID, (ClassCreatorFunc)LAGALittleArrows::CreateAGALittleArrowsStream);
}
// end <06/05/96 ca>
LAGALittleArrows*
LAGALittleArrows::CreateAGALittleArrowsStream( LStream *inStream)
{
return (new LAGALittleArrows(inStream));
}
LAGALittleArrows::LAGALittleArrows()
:LControl()
{
}
LAGALittleArrows::LAGALittleArrows(const SPaneInfo &inPaneInfo,
MessageT inValueMessage,
ResIDT traitsID,
Str255 title)
:LControl(inPaneInfo,inValueMessage,0,0,1)
{
mTitle = title;
mTextTraitsID = traitsID;
}
LAGALittleArrows::LAGALittleArrows( LStream *inStream)
: LControl(inStream)
{
Int16 controlKind;
Int32 macRefCon;
inStream->ReadData(&controlKind, sizeof(Int16)); // ignored
inStream->ReadData(&mTextTraitsID, sizeof(ResIDT));
inStream->ReadPString(mTitle);
inStream->ReadData(&macRefCon, sizeof(Int32)); // ignored
}
LAGALittleArrows::~LAGALittleArrows()
{
}
void
LAGALittleArrows::DrawText ( )
{
Rect frame;
FontInfo info;
short space,
alignment;
RGBColor textColor;
if (CalcLocalFrameRect(frame)) {
frame.left += kTextStart;
alignment = UTextTraits::SetPortTextTraits(mTextTraitsID);
// Get the font centered top/bottom
::GetFontInfo(&info);
space = (frame.bottom - frame.top - (info.ascent + info.descent))/2;
frame.top += space;
frame.bottom -= space;
if (mInColor) {
::GetForeColor(&textColor);
ApplyForeAndBackColors();
if (mEnabled == triState_On) // <06/27/96 ca>
::RGBForeColor(&textColor);
else
::RGBForeColor(&gAGAColorArray[7]);
}
UTextDrawing::DrawWithJustification((Ptr)&mTitle[1], mTitle[0], frame, alignment);
}
}
void
LAGALittleArrows::DrawArrow(Boolean upArrow, Boolean pushed)
{
PolyHandle aPoly;
Rect inSpace;
CalcLocalFrameRect(inSpace);
inSpace.right = inSpace.left + kArrowWidth;
if (!upArrow) inSpace.top += kArrowHeight-1;
inSpace.bottom = inSpace.top + kArrowHeight;
::PenNormal();
if (mInColor) {
ApplyForeAndBackColors();
if (mEnabled != triState_On) // <06/27/96 ca>
::RGBForeColor(&gAGAColorArray[7]);
}
else if (mEnabled != triState_On) // <06/27/96 ca>
::PenPat(&qd.gray);
::FrameRect(&inSpace);
::InsetRect(&inSpace,1,1);
if (pushed) {
if (mInColor) ::RGBForeColor(&gAGAColorArray[8]);
}
else {
if (!mInColor) ::ForeColor(whiteColor);
else ::RGBForeColor(&gAGAColorArray[2]);
}
::PaintRect(&inSpace);
if (mInColor) {
if (mEnabled != triState_On) // <06/27/96 ca>
::RGBForeColor(&gAGAColorArray[1]);
else if (pushed)
::RGBForeColor(&gAGAColorArray[10]);
else
ForeColor(whiteColor);
::MoveTo(inSpace.left,inSpace.bottom-2);
::LineTo(inSpace.left,inSpace.top);
::LineTo(inSpace.right-1,inSpace.top);
if (pushed)
::RGBForeColor(&gAGAColorArray[6]);
else
::RGBForeColor(&gAGAColorArray[5]);
::MoveTo(inSpace.right-1,inSpace.top+1);
::LineTo(inSpace.right-1,inSpace.bottom-1);
::LineTo(inSpace.left+1,inSpace.bottom-1);
}
if (mEnabled != triState_On) { // <06/27/96 ca>
if (mInColor) ::RGBForeColor(&gAGAColorArray[7]);
else ::PenPat(&qd.gray);
}
else if (pushed)
::ForeColor(whiteColor);
else
::ForeColor(blackColor);
if (upArrow) {
::MoveTo(inSpace.left+2,inSpace.bottom-3);
aPoly = ::OpenPoly();
::Line(7,0);
::Line(-4,-4);
::Line(-3,3);
}
else {
::MoveTo(inSpace.left+2,inSpace.top+3);
aPoly = ::OpenPoly();
::Line(7,0);
::Line(-4,4);
::Line(-4,-4);
}
::ClosePoly();
::PaintPoly(aPoly);
::KillPoly(aPoly);
}
void
LAGALittleArrows::DrawSelf()
{
StColorPenState savedState;
savedState.Normalize();
mInColor = ::PaneInColor(this);
DrawText();
DrawArrow(TRUE,FALSE);
DrawArrow(FALSE,FALSE);
}
Int16
LAGALittleArrows::FindHotSpot( Point localPt )
// Control has an up-arrow (1) and a down-arrow (2)
{
Rect aRect;
CalcLocalFrameRect(aRect);
if (localPt.v > aRect.top + kArrowHeight) return kDownArrow;
else return kUpArrow;
}
void
LAGALittleArrows::HotSpotAction(short inHotSpot, Boolean inCurrInside, Boolean inPrevInside)
{
SysPPtr sysP;
Int32 value;
if (inCurrInside != inPrevInside) {
StColorPenState savedState;
FocusDraw();
DrawArrow(inHotSpot==kUpArrow, inCurrInside);
if (inCurrInside) {
sysP = ::GetSysPPtr(); // Get repeat delay from PRAM
mNextBroadcast = ::TickCount() + 4*((sysP->kbdPrint>>12) & 0xF);
mDoneOne = FALSE;
}
}
if (inCurrInside) {
if (::TickCount() >= mNextBroadcast) {
value = inHotSpot;
BroadcastMessage(mValueMessage,(void*) &value);
sysP = ::GetSysPPtr(); // Get repeat rate from PRAM
mNextBroadcast = mNextBroadcast + 2*((sysP->kbdPrint>>8) & 0xF);
mDoneOne = true;
}
}
}
void
LAGALittleArrows::HotSpotResult(short inHotSpot)
{
HotSpotAction(inHotSpot, false, true);
if (!mDoneOne) {
Int32 value = inHotSpot;
BroadcastMessage(mValueMessage,(void*) &value);
}
}